package upicgame.cart.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import upicgame.cart.service.AccountService;
import upicgame.entity.Library;
import upicgame.gamelibrary.service.LibraryService;
import upicgame.utils.Page;

@Controller
public class AccountController {
	@Autowired
	private AccountService as;

	@RequestMapping("singleAccount")
	public String singleAccount(@RequestParam(value = "uid", required = true) Integer uid,
			@RequestParam(value = "gid", required = true) Integer gid, Model model) {
		String result = as.singleAccount(uid, gid);
		if (result.equals("SUCCESS")) {
			return "redirect:/showLibrary?uid=" + uid;
		} else if (result.equals("余额不足")) { 
			model.addAttribute("msg", result);
			return "redirect:/items?uid=" + uid;
		} else {
			model.addAttribute("msg", result);
			return "redirect:/items?uid=" + uid;
		}
	}

	@RequestMapping("allAccount")
	public String allAccount(@RequestParam(value = "uid", required = true) Integer uid, Model model) {
		String result = as.allAccount(uid);
		if (result.equals("SUCCESS")) {
			return "redirect:/showLibrary?uid=" + uid;
		} else if (result.equals("余额不足")) {
			model.addAttribute("msg", result);
			return "redirect:/items?uid=" + uid;
		} else {
			model.addAttribute("msg", result);
			return "redirect:/items?uid=" + uid;
		}
	}
}
